package com.banshuibao.bsb_android.http;


import com.banshuibao.bsb_android.model.CalenderFormModel;
import com.zx.uploadlibrary.listener.impl.UIProgressListener;

import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.Callback;

/**
 * Created by zyh on 2017/2/13.
 */

public class HttpUtil {

    public static void doPost(final String url, final Object body, OnHttpResponseListener onResponseListener) {
        Observable.create(new OkHttpPostRequest(url, body)).
                subscribeOn(Schedulers.io()).
                observeOn(AndroidSchedulers.mainThread()).
                subscribe(new OkHttpResponse(onResponseListener));
    }

    public static void doGet(final String url, OnHttpResponseListener onResponseListener) {
        Observable.create(new OkHttpGetRequest(url)).
                subscribeOn(Schedulers.io()).
                observeOn(AndroidSchedulers.mainThread()).
                subscribe(new OkHttpResponse(onResponseListener));
    }

    public static void doUpload(String url, String path, UIProgressListener listener, OnHttpResponseListener onResponseListener) {
        Observable.create(new OkHttpUpload(url, path, listener)).
                subscribeOn(Schedulers.io()).
                observeOn(AndroidSchedulers.mainThread()).
                subscribe(new OkHttpResponse(onResponseListener));
    }

    public static void doDownload(String url, UIProgressListener listener, Callback callback) {
        new OkHttpDownload(url, listener, callback).download();
    }

    public static void do2366Web(final String url, CalenderFormModel.Body body, OnHttpResponseListener onResponseListener) {
        Observable.create(new OkHttp2366PostRequest(url, body)).
                subscribeOn(Schedulers.io()).
                observeOn(AndroidSchedulers.mainThread()).
                subscribe(new Ok2366HttpResponse(onResponseListener));
    }
}
